package ter.find.pattern;

import java.awt.Color;
import java.util.Arrays;
import java.util.List;

import javax.swing.table.AbstractTableModel;
import ter.find.pattern.gui.ChangeForm.SymbolClass;

public class BaseSymbolClassModel extends AbstractTableModel  {
	
   
private boolean DEBUG = false;
	
	
	private int attribSymbol=3;
	
	
	private static final long serialVersionUID = 1L;
	private final String[] columnNames = {"Symbole","Valeur minimale","Valeur maximale"};
    private Object[][] data;
    
   
    public BaseSymbolClassModel(List<SymbolClass> sc){
    	
    	data=new Object[sc.size()][attribSymbol];
		for(int i=0;i<sc.size();i++){
			SymbolClass sC=sc.get(i);
			String sym=sC.getSymb();
			double vmin=sC.getValeurMin();
			double vmax=sC.getValeurMax();
			//Value to String
			
			
			for(int j=0;j<attribSymbol;j++){
				if(j==0){
					data[i][j]=sym;		
				}
				
				if(j==1){
					data[i][j]=vmin;		
				}
				
				if(j==2){
					data[i][j]=vmax;		
				}
				
			}
			//Create a new motif à chaque boucle 
			//motifString.add(new Motif(new Boolean(false),itemString, idString, sup,count));
		}
		
    	
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        return data.length;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return data[row][col];
    }


    public Class<? extends Object> getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
    
    List<Color> rowColours = Arrays.asList(
            Color.RED,
            Color.GREEN,
            Color.CYAN
        );

        public void setRowColour(int row, Color c) {
            rowColours.set(row, c);
            fireTableRowsUpdated(row, row);
        }

        public Color getRowColour(int row) {
            return rowColours.get(row);
        }
    

    public boolean isCellEditable(int row, int col) {

        if (col < 2) {
            return true;
        } else {
            return false;
        }
    }


    public void setValueAt(Object value, int row, int col) {
        if (DEBUG) {
            System.out.println("Setting value at " + row + "," + col
                               + " to " + value
                               + " (an instance of "
                               + value.getClass() + ")");
        }

        data[row][col] = value;
        fireTableCellUpdated(row, col);

        if (DEBUG) {
            System.out.println("New value of data:");
            printDebugData();
        }
    }

    private void printDebugData() {
        int numRows = getRowCount();
        int numCols = getColumnCount();

        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + data[i][j]);
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }


}
